<?php
/**
 * ajax后台程序基类
 */

class App_Ajax extends App_Web
{
    protected function checkAuth()
    {
        parent::checkAuth();

        $this->setCommonPara();
    }

    protected function outputHead()
    {
    }

    protected function outputTail()
    {
    }

    protected function outputHttp()
    {
    }

    protected function showError($ex)
    {
        if ($ex->getMessage() == "common:fast operate")
        {
            $this->goToErrorFast();
        }
        else
        {
            $rawmsg = $ex->getMessage();
            if (isset(Conf_Exception::$exceptions[$rawmsg]))
            {
            	list($errno,$errmsg) = Conf_Exception::$exceptions[$rawmsg];
            }
            else
            {
            	$errno = $ex->getCode();
            	$errmsg = Conf_Exception::DEFAULT_ERRMSG;
            }

            $response = new Response_Ajax();
            $response->setError(array(
                "errmsg" => $errmsg,
                "errno" => $errno,
                "trace" => $rawmsg . "\n" . $ex->getTrace(),
            ));
            $response->send();
            Tool_Log::debug('@app_ajax', "code:".$ex->getCode()."\nerror:" . $ex->getMessage() . "\n" . var_export($ex->getTrace(),true));
        }
    }

    public function goToErrorFast()
    {
        $response = new Response_Ajax();
        $response->seeOther("/common/error_fast.php");
        $response->send();
        exit;
    }
}
?>